// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.core.metadata;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf 2007-12-12 qiang.zhang $
 * 
 */
public class MetadataColumn implements Cloneable {

    private MetadataTable metadataTable;

    private String columnName = ""; //$NON-NLS-1$

    private boolean key = true;

    private String type = ""; //$NON-NLS-1$

    private boolean nullable = false;

    private Integer length = 0;

    private Integer precision = 0;

    private String defaut = ""; //$NON-NLS-1$

    private String comment = ""; //$NON-NLS-1$

    private String pattern = ""; //$NON-NLS-1$

    private boolean isSelected;

    private boolean isForeignKey;

    /**
     * Qiang.Zhang.Adolf@gmail.com MetadataColumn constructor comment.
     */
    public MetadataColumn() {
    }

    /**
     * Getter for columnName.
     * 
     * @return the columnName
     */
    public String getColumnName() {
        return this.columnName;
    }

    /**
     * Sets the columnName.
     * 
     * @param columnName the columnName to set
     */
    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    /**
     * Getter for metadataTable.
     * 
     * @return the metadataTable
     */
    public MetadataTable getMetadataTable() {
        return this.metadataTable;
    }

    /**
     * Sets the metadataTable.
     * 
     * @param metadataTable the metadataTable to set
     */
    public void setMetadataTable(MetadataTable metadataTable) {
        this.metadataTable = metadataTable;
    }

    /**
     * Getter for key.
     * 
     * @return the key
     */
    public boolean isKey() {
        return this.key;
    }

    /**
     * Sets the key.
     * 
     * @param key the key to set
     */
    public void setKey(boolean key) {
        this.key = key;
    }

    /**
     * Getter for type.
     * 
     * @return the type
     */
    public String getType() {
        return this.type;
    }

    /**
     * Sets the type.
     * 
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * Getter for nullable.
     * 
     * @return the nullable
     */
    public boolean isNullable() {
        return this.nullable;
    }

    /**
     * Sets the nullable.
     * 
     * @param nullable the nullable to set
     */
    public void setNullable(boolean nullable) {
        this.nullable = nullable;
    }

    /**
     * Getter for length.
     * 
     * @return the length
     */
    public Integer getLength() {
        return this.length;
    }

    /**
     * Sets the length.
     * 
     * @param length the length to set
     */
    public void setLength(Integer length) {
        this.length = length;
    }

    /**
     * Getter for precision.
     * 
     * @return the precision
     */
    public Integer getPrecision() {
        return this.precision;
    }

    /**
     * Sets the precision.
     * 
     * @param precision the precision to set
     */
    public void setPrecision(Integer precision) {
        this.precision = precision;
    }

    /**
     * Getter for defaut.
     * 
     * @return the defaut
     */
    public String getDefaut() {
        return this.defaut;
    }

    /**
     * Sets the defaut.
     * 
     * @param defaut the defaut to set
     */
    public void setDefaut(String defaut) {
        this.defaut = defaut;
    }

    /**
     * Getter for comment.
     * 
     * @return the comment
     */
    public String getComment() {
        return this.comment;
    }

    /**
     * Sets the comment.
     * 
     * @param comment the comment to set
     */
    public void setComment(String comment) {
        this.comment = comment;
    }

    /**
     * Getter for pattern.
     * 
     * @return the pattern
     */
    public String getPattern() {
        return this.pattern;
    }

    /**
     * Sets the pattern.
     * 
     * @param pattern the pattern to set
     */
    public void setPattern(String pattern) {
        this.pattern = pattern;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#clone()
     */
    @Override
    public MetadataColumn clone() {
        MetadataColumn column = null;
        try {
            column = (MetadataColumn) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

        return column;
    }

    public boolean sameAs(MetadataColumn column) {
        if (this == column) {
            return true;
        }
        if (!column.getColumnName().equals(getColumnName())) {
            return false;
        }
        if (!column.key == this.key) {
            return false;
        }

        if (!column.nullable == this.nullable) {
            return false;
        }
        if (!column.comment.equals(this.comment)) {
            return false;
        }
        if (!column.defaut.equals(this.defaut)) {
            return false;
        }
        if (!column.length.equals(this.length)) {
            return false;
        }

        if (!column.pattern.equals(this.pattern)) {
            return false;
        }
        if (!column.precision.equals(this.precision)) {
            return false;
        }
        if (!column.type.equals(this.type)) {
            return false;
        }
        return true;
    }

    public boolean isSelected() {
        return this.isSelected;
    }

    public void setSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }

    public boolean isForeignKey() {
        return this.isForeignKey;
    }

    public void setForeignKey(boolean isForeignKey) {
        this.isForeignKey = isForeignKey;
    }
}
